package order

import (
	"github.com/gin-gonic/gin"
	"mallgo/internal/common/response"
	"mallgo/internal/resources/order/api/domain/request"
	"mallgo/internal/resources/order/resource"
)

type OrderController struct {
	res *resource.OrderResource
}

func NewOrderController(res *resource.OrderResource) *OrderController {
	return &OrderController{
		res: res,
	}
}

func (c *OrderController) CreateOrder(ctx *gin.Context) {

	var req request.OrderRequest

	// 绑定并验证请求数据
	if err := ctx.ShouldBindJSON(&req); err != nil {
		ctx.JSON(200, response.Error(501, "请求参数错误"))
		return
	}
	res := c.res.CreateOrder(&req)

	ctx.JSON(200, res)
}
